<?php

namespace App\Http\Requests\Admins;

use Illuminate\Foundation\Http\FormRequest;

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return TRUE;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
    		$rules = [
            'name'=>'required',
        ];
        if (request('id','')) {
            $rules['username'] = 'required|unique:users,username,'.$this->id;
            $rules['email'] = 'required|unique:users,email,'.$this->id;
        }else{
            $rules['username'] = 'required|unique:users,username';
            $rules['email'] = 'required|unique:users,email';
        }
        return $rules;
    }
	
	public function messages(){
		return [
			'name.required'=>"名称不能为空",
			'name.unique'=>"名称不能重复",
			'username.required'=>"用户名不能为空",
			'username.unique'=>"用户名不能重复",
			'email.required'=>"邮件不能为空",
			'email.unique'=>"邮件不能重复",
		];
	}
}
